// 用户相关类型
export interface User {
  id: number;
  username: string;
  email: string;
  phone?: string;
  real_name?: string;
  id_card?: string;
  risk_level: number;
  total_assets: number;
  available_cash: number;
  investment_experience: string;
  isAdmin?: boolean;
  role?: string;
  created_at: string;
  updated_at: string;
}

export interface LoginRequest {
  username: string;
  password: string;
}

export interface RegisterRequest {
  username: string;
  email: string;
  password: string;
  password_confirm: string;
  phone?: string;
  real_name?: string;
}

export interface AuthResponse {
  token: string;
  user: User;
}

// 产品相关类型
export interface ProductCategory {
  id: number;
  name: string;
  description?: string;
  created_at: string;
}

export interface Product {
  id: number;
  category: ProductCategory;
  name: string;
  code: string;
  description?: string;
  product_type: string;
  risk_level: number;
  min_investment: number;
  management_fee: number;
  status: string;
  created_at: string;
  updated_at: string;
}

export interface ProductPrice {
  id: number;
  product: number;
  price: number;
  price_date: string;
  created_at: string;
}

export interface ProductPerformance {
  id: number;
  product: number;
  return_1d: number;
  return_1w: number;
  return_1m: number;
  return_3m: number;
  return_6m: number;
  return_1y: number;
  return_3y: number;
  volatility: number;
  sharpe_ratio: number;
  max_drawdown: number;
  performance_date: string;
  created_at: string;
}

// 投资组合相关类型
export interface Portfolio {
  id: number;
  user: number;
  name: string;
  description?: string;
  target_return: number;
  risk_level: number;
  total_value: number;
  total_return: number;
  created_at: string;
  updated_at: string;
}

export interface PortfolioHolding {
  id: number;
  portfolio: number;
  product: Product;
  quantity: number;
  average_price: number;
  current_value: number;
  profit_loss: number;
  profit_loss_rate: number;
  created_at: string;
  updated_at: string;
}

export interface Transaction {
  id: number;
  portfolio: number;
  product: Product;
  transaction_type: 'buy' | 'sell';
  quantity: number;
  price: number;
  amount: number;
  fee: number;
  created_at: string;
}

export interface StopLossSetting {
  id: number;
  portfolio: number;
  stop_loss_type: 'fixed' | 'trailing' | 'technical';
  fixed_percentage?: number;
  trailing_percentage?: number;
  technical_indicator?: string;
  is_active: boolean;
  created_at: string;
  updated_at: string;
}

// 数据服务相关类型
export interface FundData {
  id: number;
  fund_code: string;
  fund_name: string;
  fund_type: string;
  fund_type_display?: string;
  fund_company: string;
  establishment_date: string;
  fund_manager: string;
  fund_size: number;
  management_fee: number;
  custodian_fee: number;
  risk_level: number;
  annual_return: number;
  created_at: string;
  updated_at: string;
}

export interface FundNetValue {
  id: number;
  fund: FundData;
  net_value: number;
  accumulated_value: number;
  value_date: string;
  daily_return: number;
  created_at: string;
}

export interface MarketData {
  id: number;
  indicator_type: string;
  indicator_name: string;
  indicator_value: number;
  change_value: number;
  change_percent: number;
  data_date: string;
  created_at: string;
}

// API响应类型
export interface ApiResponse<T> {
  data: T;
  message?: string;
  status: number;
}

export interface PaginatedResponse<T> {
  results: T[];
  total_count: number;
  page: number;
  page_size: number;
  total_pages: number;
}

// 资产配置相关类型
export interface AssetAllocation {
  total_amount: number;
  risk_level: number;
}

export interface AllocationResult {
  stock_amount: number;
  bond_amount: number;
  fund_amount: number;
  cash_amount: number;
  allocation_ratios: {
    stock: number;
    bond: number;
    fund: number;
    cash: number;
  };
}

// 表单相关类型
export interface FormErrors {
  [key: string]: string[];
}

// 通用类型
export interface SelectOption {
  label: string;
  value: string | number;
}

export interface TableColumn {
  title: string;
  dataIndex: string;
  key: string;
  width?: number;
  render?: (value: any, record: any) => React.ReactNode;
}

// 风险等级映射
export const RISK_LEVELS = {
  1: '保守型',
  2: '稳健型',
  3: '平衡型',
  4: '成长型',
  5: '激进型'
} as const;

// 产品状态映射
export const PRODUCT_STATUS = {
  active: '正常',
  suspended: '暂停',
  closed: '关闭'
} as const;

// 交易类型映射
export const TRANSACTION_TYPES = {
  buy: '买入',
  sell: '卖出'
} as const;